package com.naiterui.ehp.bs.pc.modules.common.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.pc.modules.common.entity.CmsUserLabel;
import com.naiterui.ehp.bs.pc.modules.common.mapper.CmsUserLabelMapper;
import com.naiterui.ehp.bs.pc.modules.common.service.ICmsUserLabelService;

/**
 * @Description 用户标签
 * @Author gongbaoqiang
 * @Date 2020/5/22 2:29 PM
 */
@Service
public class CmsUserLabelServiceImpl implements ICmsUserLabelService {

    @Autowired
    private CmsUserLabelMapper userLabelMapper;

    @Override
    public boolean isDoctorExpert(Long doctorId) throws BusinessException {
        CmsUserLabel userLabel = this.userLabelMapper.selectOne(this.getDoctorExpertWrapper(doctorId));
        if (userLabel == null) {
            return false;
        }
        return true;
    }

    @Override
    public void insertDoctorExpert(Long doctorId) {
        CmsUserLabel userLabel = new CmsUserLabel();
        userLabel.setUserId(doctorId);
        userLabel.setLabelId(CmsUserLabel.LABEL_ID_DOCTOR_EXPERT);
        userLabel.setUserType(CmsUserLabel.USER_TYPE_DOCTOR);
        this.userLabelMapper.insert(userLabel);
    }

    @Override
    public void removeDoctorExpert(Long doctorId) {
        this.userLabelMapper.delete(this.getDoctorExpertWrapper(doctorId));
    }

    private QueryWrapper getDoctorExpertWrapper(Long doctorId) {
        QueryWrapper<CmsUserLabel> wrapper = new QueryWrapper<>();
        wrapper.eq("label_id", CmsUserLabel.LABEL_ID_DOCTOR_EXPERT);
        wrapper.eq("user_type", CmsUserLabel.USER_TYPE_DOCTOR);
        wrapper.eq("user_id", doctorId);
        return wrapper;
    }

}
